<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>XS-blog注册页面</title>
    <link rel="stylesheet" href="css/common.css">
    <link rel="stylesheet" href="css/blog_login.css">
</head>
<style>
    body{
        background-image: url("img/reg.png");
    }
</style>
<script src="js/jquery.min.js"></script>
<script>
    $(function (){
        $("#submit").click(function (){
            var username=$("#username").val();
            var password=$("#password").val();
            if (username.trim() == "" || password.trim()==""){
                alert("用户名或密码不能为空！");
                window.location.href="register.html";
                return;
            }

            $.ajax({
                url: "/user/register",
                data:{"username":username,"password":password},
                type:"POST",
                dataType:"json",
                success:function (data){
                    console.log(data);
                    if (data.status==0){
                        alert("注册成功！");
                        window.location.href="blog_login.html";
                    }else {
                        alert("注册失败，可能是当前用户名已存在");
                        $("#username").val("");
                        $("#password").val("");
                        window.location.href="register.html";
                    }
                }
            });
        });
    });
</script>
<body>
<!-- 导航栏 -->
<div class="nav">
    <img src="img/tom.jpeg" alt="">
    <span>XS-blog</span>
    <!-- 空白元素 实现占位 -->
    <div class="spacer"></div>
    <a href="blog_login.html">回到登录页面</a>
</div>
<div class="login-container">

        <div class="login-dialog">
            <h3>注册</h3>
            <div class="row">
                <span>用户名</span>
                <input type="text" id="username" name="username">
            </div>
            <div class="row">
                <span>密码</span>
                <input type="password" id="password" name="password">
            </div>
            <div class="row">
                <!-- <button>提交</button> -->
                <input type="submit" id="submit" value="注册用户">
            </div>
        </div>

</div>
</body>
</html>